/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import entities.*;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.RollbackException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import logica.*;
import renders.AltaAlquilerRender;

/**
 *
 * @author Smuggler
 */
public class AltaReservas extends JPanel {

    private Logs logs;
    private AltaClienteReserva nuevoCliente;
    public static JFrame frame;
    private List clienteLista;
    entities.Alquileres a;
    String tipoAlquiler = "R";
    String tipoBusqueda;
    private static Clientes cliente;
    private List listactualizaTabla;
    ExisteAlquiler existealquiler = new ExisteAlquiler();
    private boolean editando = false;
    private Usuarios usuario;
    private Integer idReserva;
    private BusquedaCliente buscarCliente;
    private Double montoReservaAnterior;

    public AltaReservas(Usuarios usuario, Integer idReserva) {
        initComponents();
        buttonGroup1.add(reservaRadioButton);
        buttonGroup1.add(reservaFirmeRadioButton);
        buttonGroup1.add(ocupadoRadioButton);
        buttonGroup1.add(canceladaRadioButton);

        buttonGroup2.add(reservaBusquedaRadioButton);
        buttonGroup2.add(reservaFirmeBusquedaRadioButton);
        buttonGroup2.add(ambasReservasBusquedaRadioButton);
        habilitarBotonesBusqueda(true);

        if (!Beans.isDesignTime()) {
            entityManager.getTransaction().begin();
        }

        this.usuario = usuario;
        this.idReserva = idReserva;

        if (idReserva != null) {
            actualizaTablaId(idReserva);
        }
        setearComboBox();
        focusFechaActual();
    }

    private Integer getIDReserva(UnidadesAlojamiento idUnidadAlojamiento, Clientes idCliente, Date fechaArribo, Date fechaPartida) {
        Query queryIDReserva;
        Alquileres reserva;
        queryIDReserva = entityManager.createNamedQuery("Alquileres.findByAll");
        queryIDReserva.setParameter("idUnidadAlojamiento", idUnidadAlojamiento);
        queryIDReserva.setParameter("idCliente", idCliente);
        queryIDReserva.setParameter("fechaArribo", fechaArribo);
        queryIDReserva.setParameter("fechaPartida", fechaPartida);
        reserva = (Alquileres) queryIDReserva.getSingleResult();
        return reserva.getIdAlquiler();
    }

    private void setearComboBox() {
        Query queryUnidades = entityManager.createNamedQuery("UnidadesAlojamiento.findAll");
        List<UnidadesAlojamiento> unidadesList = queryUnidades.getResultList();
        for (UnidadesAlojamiento unidadesAlojamiento : unidadesList) {
            unidadAlojamientoBusquedaComboBox.addItem(unidadesAlojamiento);
        }
        UnidadesAlojamiento ua = new UnidadesAlojamiento();
        ua.setNombre("TODOS");
        unidadAlojamientoBusquedaComboBox.addItem(ua);
        unidadAlojamientoBusquedaComboBox.setSelectedItem(ua);
    }

    public JFrame getFrame() {
        return frame;
    }

    public void setFrame(JFrame frame) {
        AltaReservas.frame = frame;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("SIAATPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Alquileres a WHERE ((a.tipoAlquiler = 'R' ) OR (a.tipoAlquiler = 'F'))ORDER BY a.fechaArribo DESC");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        unidadesAlojamientoQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT u FROM UnidadesAlojamiento u");
        unidadesAlojamientoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : unidadesAlojamientoQuery.getResultList();
        unidadesAlojamientoQuery1 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT u FROM UnidadesAlojamiento u");
        unidadesAlojamientoList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : unidadesAlojamientoQuery1.getResultList();
        clientesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Clientes c  ORDER BY c.apellido");
        clientesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clientesQuery.getResultList();
        clientesQuery1 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Clientes c");
        clientesList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clientesQuery1.getResultList();
        buttonGroup1 = new javax.swing.ButtonGroup();
        clientesQuery2 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Clientes c");
        clientesList2 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clientesQuery2.getResultList();
        buttonGroup2 = new javax.swing.ButtonGroup();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        idUnidadAlojamientoLabel = new javax.swing.JLabel();
        idClienteLabel = new javax.swing.JLabel();
        estadoAlquilerLabel = new javax.swing.JLabel();
        fechaArriboLabel = new javax.swing.JLabel();
        fechaPartidaLabel = new javax.swing.JLabel();
        cantidadPersonasLabel = new javax.swing.JLabel();
        montoTotalLabel = new javax.swing.JLabel();
        montoReservaLabel = new javax.swing.JLabel();
        montoTotalField = new javax.swing.JTextField();
        montoReservaField = new javax.swing.JTextField();
        guardarButton = new javax.swing.JButton();
        nuevoButton = new javax.swing.JButton();
        fechaArriboDateChooser = new com.toedter.calendar.JDateChooser();
        fechaPartidaDateChooser = new com.toedter.calendar.JDateChooser();
        unidadAlojamientoComboBox = new javax.swing.JComboBox();
        agregarClienteButton = new javax.swing.JButton();
        reservaRadioButton = new javax.swing.JRadioButton();
        reservaFirmeRadioButton = new javax.swing.JRadioButton();
        ocupadoRadioButton = new javax.swing.JRadioButton();
        cancelarButton = new javax.swing.JButton();
        cantidadPersonasComboBox = new javax.swing.JComboBox();
        ayudaLabel = new javax.swing.JLabel();
        checkInButton = new javax.swing.JButton();
        contratoButton = new javax.swing.JButton();
        buscarClienteButton = new javax.swing.JButton();
        clienteTextField = new javax.swing.JTextField();
        canceladaRadioButton = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        unidadAlojamientoLabel = new javax.swing.JLabel();
        unidadAlojamientoBusquedaComboBox = new javax.swing.JComboBox();
        fechaArriboLabel1 = new javax.swing.JLabel();
        reservaBusquedaRadioButton = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        fechaPartidaDateChooser1 = new com.toedter.calendar.JDateChooser();
        apellidoLabel = new javax.swing.JLabel();
        fechaArriboDateChooser1 = new com.toedter.calendar.JDateChooser();
        resetButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        apellidoField = new javax.swing.JTextField();
        reservaFirmeBusquedaRadioButton = new javax.swing.JRadioButton();
        ambasReservasBusquedaRadioButton = new javax.swing.JRadioButton();
        buscarButton = new javax.swing.JButton();
        exportarExcelButton = new javax.swing.JButton();
        sendEmail = new javax.swing.JButton();

        FormListener formListener = new FormListener();

        masterTable.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idAlquiler}"));
        columnBinding.setColumnName("Codigo Reserva");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idUnidadAlojamiento}"));
        columnBinding.setColumnName("Unidad Alojamiento");
        columnBinding.setColumnClass(entities.UnidadesAlojamiento.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idCliente}"));
        columnBinding.setColumnName("Cliente");
        columnBinding.setColumnClass(entities.Clientes.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tipoAlquiler}"));
        columnBinding.setColumnName("Estado Alquiler");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaArribo}"));
        columnBinding.setColumnName("Fecha Arribo");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaPartida}"));
        columnBinding.setColumnName("Fecha Partida");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${montoTotal}"));
        columnBinding.setColumnName("Monto Total");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${montoReserva}"));
        columnBinding.setColumnName("Monto Reserva");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadPersonas}"));
        columnBinding.setColumnName("Cantidad Personas");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addMouseListener(formListener);
        masterScrollPane.setViewportView(masterTable);
        masterTable.getColumnModel().getColumn(3).setCellRenderer(new AltaAlquilerRender());

        idUnidadAlojamientoLabel.setText("Unidad Alojamiento:");

        idClienteLabel.setText("Cliente :");

        estadoAlquilerLabel.setText("Estado del  Alquiler:");

        fechaArriboLabel.setText("Fecha Arribo:");

        fechaPartidaLabel.setText("Fecha Partida:");

        cantidadPersonasLabel.setText("Cantidad Personas:");

        montoTotalLabel.setText("Monto Total:");

        montoReservaLabel.setText("Monto Reserva:");

        montoTotalField.setEnabled(false);
        montoTotalField.addKeyListener(formListener);

        montoReservaField.setEnabled(false);
        montoReservaField.addKeyListener(formListener);

        guardarButton.setBackground(new java.awt.Color(1, 154, 210));
        guardarButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        guardarButton.setForeground(new java.awt.Color(255, 255, 255));
        guardarButton.setText("Guardar");
        guardarButton.setEnabled(false);
        guardarButton.addActionListener(formListener);

        nuevoButton.setBackground(new java.awt.Color(1, 154, 210));
        nuevoButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        nuevoButton.setForeground(new java.awt.Color(255, 255, 255));
        nuevoButton.setText("Nuevo");
        nuevoButton.addActionListener(formListener);

        fechaArriboDateChooser.setEnabled(false);

        fechaPartidaDateChooser.setEnabled(false);

        unidadAlojamientoComboBox.setEnabled(false);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, unidadesAlojamientoList, unidadAlojamientoComboBox, "");
        bindingGroup.addBinding(jComboBoxBinding);

        unidadAlojamientoComboBox.addFocusListener(formListener);

        agregarClienteButton.setBackground(new java.awt.Color(1, 154, 210));
        agregarClienteButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        agregarClienteButton.setForeground(new java.awt.Color(255, 255, 255));
        agregarClienteButton.setText("Nuevo Cliente");
        agregarClienteButton.setEnabled(false);
        agregarClienteButton.addActionListener(formListener);

        reservaRadioButton.setSelected(true);
        reservaRadioButton.setText("Reserva");
        reservaRadioButton.setEnabled(false);
        reservaRadioButton.addActionListener(formListener);

        reservaFirmeRadioButton.setText("Reserva Firme");
        reservaFirmeRadioButton.setEnabled(false);
        reservaFirmeRadioButton.addActionListener(formListener);

        ocupadoRadioButton.setText("Ocupado");
        ocupadoRadioButton.setEnabled(false);
        ocupadoRadioButton.addActionListener(formListener);

        cancelarButton.setBackground(new java.awt.Color(1, 154, 210));
        cancelarButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        cancelarButton.setForeground(new java.awt.Color(255, 255, 255));
        cancelarButton.setText("Cancelar");
        cancelarButton.setEnabled(false);
        cancelarButton.addActionListener(formListener);

        cantidadPersonasComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4" }));
        cantidadPersonasComboBox.setEnabled(false);

        ayudaLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help.png"))); // NOI18N
        ayudaLabel.addMouseListener(formListener);

        checkInButton.setBackground(new java.awt.Color(255, 153, 0));
        checkInButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        checkInButton.setForeground(new java.awt.Color(255, 255, 255));
        checkInButton.setText("Generar Check-In Card");
        checkInButton.setEnabled(false);
        checkInButton.addActionListener(formListener);

        contratoButton.setBackground(new java.awt.Color(255, 153, 0));
        contratoButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        contratoButton.setForeground(new java.awt.Color(255, 255, 255));
        contratoButton.setText("Generar Contrato de Alquiler");
        contratoButton.setEnabled(false);
        contratoButton.addActionListener(formListener);

        buscarClienteButton.setBackground(new java.awt.Color(1, 154, 210));
        buscarClienteButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        buscarClienteButton.setForeground(new java.awt.Color(255, 255, 255));
        buscarClienteButton.setText("Seleccionar Cliente");
        buscarClienteButton.setEnabled(false);
        buscarClienteButton.addActionListener(formListener);

        clienteTextField.setEditable(false);
        clienteTextField.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        canceladaRadioButton.setText("Cancelada");
        canceladaRadioButton.setEnabled(false);
        canceladaRadioButton.addActionListener(formListener);

        unidadAlojamientoLabel.setText("Unidad de Alojamiento:");

        unidadAlojamientoBusquedaComboBox.setEnabled(false);

        fechaArriboLabel1.setText("Fecha Arribo:");

        reservaBusquedaRadioButton.setText("Reserva");
        reservaBusquedaRadioButton.setEnabled(false);
        reservaBusquedaRadioButton.addActionListener(formListener);

        jLabel4.setText("Fecha Partida:");

        fechaPartidaDateChooser1.setEnabled(false);

        apellidoLabel.setText("Apellido:");

        fechaArriboDateChooser1.setEnabled(false);

        resetButton.setBackground(new java.awt.Color(1, 154, 210));
        resetButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        resetButton.setForeground(new java.awt.Color(255, 255, 255));
        resetButton.setText("Resetear Busqueda");
        resetButton.setEnabled(false);
        resetButton.addActionListener(formListener);

        jLabel1.setText("Estado de Reserva:");

        apellidoField.setEnabled(false);

        reservaFirmeBusquedaRadioButton.setText("Reserva Firme");
        reservaFirmeBusquedaRadioButton.setEnabled(false);
        reservaFirmeBusquedaRadioButton.addActionListener(formListener);

        ambasReservasBusquedaRadioButton.setSelected(true);
        ambasReservasBusquedaRadioButton.setText("Ambas Reservas");
        ambasReservasBusquedaRadioButton.setEnabled(false);

        buscarButton.setBackground(new java.awt.Color(1, 154, 210));
        buscarButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        buscarButton.setForeground(new java.awt.Color(255, 255, 255));
        buscarButton.setText("Buscar");
        buscarButton.setEnabled(false);
        buscarButton.addActionListener(formListener);

        exportarExcelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/xls.png"))); // NOI18N
        exportarExcelButton.setText("Exportar");
        exportarExcelButton.addActionListener(formListener);

        sendEmail.setBackground(new java.awt.Color(255, 153, 0));
        sendEmail.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        sendEmail.setForeground(new java.awt.Color(255, 255, 255));
        sendEmail.setText("Enviar Datos de Reserva por mail");
        sendEmail.setEnabled(false);
        sendEmail.addActionListener(formListener);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(masterScrollPane)
                    .addComponent(jSeparator1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(unidadAlojamientoLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(apellidoLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(ayudaLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(exportarExcelButton)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(reservaBusquedaRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(reservaFirmeBusquedaRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(ambasReservasBusquedaRadioButton)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(buscarButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(resetButton)
                                .addGap(28, 28, 28))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(apellidoField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(unidadAlojamientoBusquedaComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(fechaArriboLabel1)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(fechaArriboDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(fechaPartidaDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(293, 293, 293))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cantidadPersonasLabel)
                                    .addComponent(montoTotalLabel)
                                    .addComponent(montoReservaLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cantidadPersonasComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(montoTotalField)
                                    .addComponent(montoReservaField, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(fechaArriboLabel)
                                    .addComponent(fechaPartidaLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(fechaArriboDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(fechaPartidaDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(381, 381, 381))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(74, 74, 74)
                                        .addComponent(checkInButton, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(contratoButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(sendEmail))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(idUnidadAlojamientoLabel)
                                                    .addComponent(idClienteLabel))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addComponent(clienteTextField)
                                                    .addComponent(unidadAlojamientoComboBox, 0, 226, Short.MAX_VALUE)))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(estadoAlquilerLabel)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(reservaRadioButton)
                                                .addGap(18, 18, 18)
                                                .addComponent(reservaFirmeRadioButton)
                                                .addGap(18, 18, 18)
                                                .addComponent(ocupadoRadioButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(canceladaRadioButton)))
                                        .addGap(41, 41, 41)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(buscarClienteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(agregarClienteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                                .addGap(131, 131, 131)))
                        .addComponent(nuevoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelarButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(guardarButton)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {guardarButton, nuevoButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(idUnidadAlojamientoLabel)
                            .addComponent(unidadAlojamientoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(idClienteLabel)
                                .addGap(6, 6, 6))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(clienteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(estadoAlquilerLabel)
                            .addComponent(reservaRadioButton)
                            .addComponent(reservaFirmeRadioButton)
                            .addComponent(ocupadoRadioButton)
                            .addComponent(canceladaRadioButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(buscarClienteButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(agregarClienteButton)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cantidadPersonasLabel)
                            .addComponent(cantidadPersonasComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(montoTotalLabel)
                            .addComponent(montoTotalField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(montoReservaLabel)
                            .addComponent(montoReservaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fechaArriboLabel)
                            .addComponent(fechaArriboDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fechaPartidaLabel)
                            .addComponent(fechaPartidaDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(guardarButton)
                            .addComponent(nuevoButton)
                            .addComponent(cancelarButton)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(checkInButton)
                        .addComponent(contratoButton)
                        .addComponent(sendEmail)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(reservaBusquedaRadioButton)
                        .addComponent(reservaFirmeBusquedaRadioButton)
                        .addComponent(ambasReservasBusquedaRadioButton)))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fechaArriboLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(apellidoLabel)
                                .addComponent(apellidoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(fechaArriboDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fechaPartidaDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(unidadAlojamientoBusquedaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(unidadAlojamientoLabel)
                                .addComponent(jLabel4)))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(resetButton)
                            .addComponent(buscarButton))
                        .addGap(16, 16, 16))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(exportarExcelButton)
                            .addComponent(ayudaLabel))
                        .addContainerGap())))
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.KeyListener, java.awt.event.MouseListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == guardarButton) {
                AltaReservas.this.guardarButtonActionPerformed(evt);
            }
            else if (evt.getSource() == nuevoButton) {
                AltaReservas.this.nuevoButtonActionPerformed(evt);
            }
            else if (evt.getSource() == agregarClienteButton) {
                AltaReservas.this.agregarClienteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reservaRadioButton) {
                AltaReservas.this.reservaRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reservaFirmeRadioButton) {
                AltaReservas.this.reservaFirmeRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == ocupadoRadioButton) {
                AltaReservas.this.ocupadoRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == cancelarButton) {
                AltaReservas.this.cancelarButtonActionPerformed(evt);
            }
            else if (evt.getSource() == checkInButton) {
                AltaReservas.this.checkInButtonActionPerformed(evt);
            }
            else if (evt.getSource() == contratoButton) {
                AltaReservas.this.contratoButtonActionPerformed(evt);
            }
            else if (evt.getSource() == buscarClienteButton) {
                AltaReservas.this.buscarClienteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == canceladaRadioButton) {
                AltaReservas.this.canceladaRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reservaBusquedaRadioButton) {
                AltaReservas.this.reservaBusquedaRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == resetButton) {
                AltaReservas.this.resetButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reservaFirmeBusquedaRadioButton) {
                AltaReservas.this.reservaFirmeBusquedaRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == buscarButton) {
                AltaReservas.this.buscarButtonActionPerformed(evt);
            }
            else if (evt.getSource() == exportarExcelButton) {
                AltaReservas.this.exportarExcelButtonActionPerformed(evt);
            }
            else if (evt.getSource() == sendEmail) {
                AltaReservas.this.sendEmailActionPerformed(evt);
            }
        }

        public void focusGained(java.awt.event.FocusEvent evt) {
        }

        public void focusLost(java.awt.event.FocusEvent evt) {
            if (evt.getSource() == unidadAlojamientoComboBox) {
                AltaReservas.this.unidadAlojamientoComboBoxFocusLost(evt);
            }
        }

        public void keyPressed(java.awt.event.KeyEvent evt) {
        }

        public void keyReleased(java.awt.event.KeyEvent evt) {
        }

        public void keyTyped(java.awt.event.KeyEvent evt) {
            if (evt.getSource() == montoTotalField) {
                AltaReservas.this.montoTotalFieldKeyTyped(evt);
            }
            else if (evt.getSource() == montoReservaField) {
                AltaReservas.this.montoReservaFieldKeyTyped(evt);
            }
        }

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == masterTable) {
                AltaReservas.this.masterTableMouseClicked(evt);
            }
        }

        public void mouseEntered(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == ayudaLabel) {
                AltaReservas.this.ayudaLabelMouseEntered(evt);
            }
        }

        public void mouseExited(java.awt.event.MouseEvent evt) {
        }

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
        }
    }// </editor-fold>//GEN-END:initComponents

    private void refrescar() {
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
        habilitarBotones(false);
        habilitarBotonesBusqueda(true);
        limpiarBotones();
        limpiarCamposBusqueda();
        montoReservaField.setText("0.0");
        montoTotalField.setText("0.0");
        sendEmail.setEnabled(false);

    }

    public void focusFechaActual() {
        //Guardo la fecha actual 
        Date fechaActualtest = new Date();
        //Recorro para buscar la fecha mas cercana a la fecha actual       
        int filaFechaCercana = 0;
        for (Alquileres alquileres : list) {
            //Si la fecha es mayor, voy guardando los numero de las filas
            if (alquileres.getFechaArribo().compareTo(fechaActualtest) > 0) {
                filaFechaCercana++;
            }
            //Si la fecha es menor o igual a la actual, me muevo a la ultima fecha mayor cercana a  la actual
            if (alquileres.getFechaArribo().compareTo(fechaActualtest) <= 0) {
                masterTable.scrollRectToVisible(masterTable.getCellRect(filaFechaCercana, 0, true));
            }
        }
    }

    private void actualizaTablaId(Integer idReserva) {
        Query query;
        query = entityManager.createNamedQuery("Alquileres.findByIdAlquiler").setParameter("idAlquiler", idReserva);
        listactualizaTabla = query.getResultList();
        list.clear();
        list.addAll(listactualizaTabla);
    }

    private void limpiarBotones() {

        unidadAlojamientoComboBox.setSelectedIndex(-1);
        clienteTextField.setText("");
        reservaRadioButton.setSelected(true);
        reservaFirmeRadioButton.setSelected(false);
        ocupadoRadioButton.setSelected(false);
        fechaArriboDateChooser.setDate(null);
        fechaPartidaDateChooser.setDate(null);
        cantidadPersonasComboBox.setSelectedIndex(-1);
        montoTotalField.setText("");
        montoReservaField.setText("");


    }
    private void nuevoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevoButtonActionPerformed
        habilitarBotones(true);
        habilitarBotonesBusqueda(false);
    }//GEN-LAST:event_nuevoButtonActionPerformed
    private void nuevoAction() {
        editando = false;
        a = new entities.Alquileres();
        montoReservaAnterior = 0.0;
        logs = new Logs();
        logs.setUsuario(usuario);
        entityManager.persist(a);
        list.add(a);
        int row = list.size() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));

    }

    private void habilitarBotones(boolean estado) {
        nuevoButton.setEnabled(!estado);
        masterTable.setEnabled(!estado);
        cancelarButton.setEnabled(estado);
        guardarButton.setEnabled(estado);
        unidadAlojamientoComboBox.setEnabled(estado);
        clienteTextField.setEnabled(estado);
        reservaRadioButton.setEnabled(estado);
        reservaFirmeRadioButton.setEnabled(estado);
        canceladaRadioButton.setEnabled(estado);
        ocupadoRadioButton.setEnabled(estado);
        fechaArriboDateChooser.setEnabled(estado);
        fechaPartidaDateChooser.setEnabled(estado);
        cantidadPersonasComboBox.setEnabled(estado);
        montoTotalField.setEnabled(estado);
        montoReservaField.setEnabled(estado);
        agregarClienteButton.setEnabled(estado);
        checkInButton.setEnabled(estado);
        contratoButton.setEnabled(estado);
        buscarClienteButton.setEnabled(estado);
        sendEmail.setEnabled(estado);

    }

    private void setearCantidadPersonasComboBox() {
        cantidadPersonasComboBox.removeAllItems();
        UnidadesAlojamiento unidadAlojamientoReservaActual = (UnidadesAlojamiento) unidadAlojamientoComboBox.getSelectedItem();
        Integer cant;
        for (int i = 1; i <= unidadAlojamientoReservaActual.getCapacidad(); i++) {
            cant = new Integer(i);
            cantidadPersonasComboBox.addItem(cant);
        }
    }

    private String identificarTipoAlquiler(String tipoAlquiler) {
        switch (tipoAlquiler) {
            case "O":
                return "Un Alquiler Ocupado";
            case "F":
                return "Una Reserva Firme";
            case "C":
                return "Una Reserva Cancelada";
            default:
                return "Una Reserva";
        }
    }

    private String formatearFecha(Date fecha) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(fecha);
        String salida = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR) + " a las " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE);
        return salida;
    }

    private void guardarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarButtonActionPerformed
        Caja movCaja;
        VistaNuevaReserva.setearMonedaPorDefecto(entityManager);
        Moneda monedaActual = VistaNuevaReserva.monedaPorDefecto;
        Double importe;
        //int returnExI = existealquiler.verificarAlquilerFecha(fechaArriboDateChooser.getDate(), fechaPartidaDateChooser.getDate(),idReserva);
        int idAlquiler;
        if (("".equals(montoReservaField.getText())) || ("".equals(montoTotalField.getText())) || ("".equals(clienteTextField.getText())) || (unidadAlojamientoComboBox.getSelectedIndex()) < 0 || (fechaArriboDateChooser.getDate() == null) || (fechaPartidaDateChooser.getDate() == null)) {
            String guardarmensaje = "";
            if ("".equals(clienteTextField.getText())) {
                guardarmensaje = guardarmensaje + "                     Cliente\n";
            }
            if (unidadAlojamientoComboBox.getSelectedIndex() < 0) {
                guardarmensaje = guardarmensaje + "                     Unidad Alojamiento\n";
            }
            if (fechaArriboDateChooser.getDate() == null) {
                guardarmensaje = guardarmensaje + "                     Fecha de Arribo\n";
            }
            if (fechaPartidaDateChooser.getDate() == null) {
                guardarmensaje = guardarmensaje + "                     Fecha de Partida\n";
            }
            if ("".equals(montoTotalField.getText())) {
                guardarmensaje = guardarmensaje + "                     Monto Total\n";
            }
            if ("".equals(montoReservaField.getText())) {
                guardarmensaje = guardarmensaje + "                     Monto de Reserva\n";
            }
            JOptionPane.showMessageDialog(this, "Seleccione :\n" + guardarmensaje, "Atención", JOptionPane.ERROR_MESSAGE, null);

        } else {
            if (editando) {
                idAlquiler = a.getIdAlquiler();
                a.setMontoReserva(Double.valueOf(montoReservaField.getText()));
                if (a.getMontoReserva().compareTo(montoReservaAnterior) < 0) {
                    JOptionPane.showMessageDialog(null, "montoReserva no puede ser menor al valor que ya tenía");
                    return;
                }
                DetalleAlquiler.editado = true;
            } else {
                idAlquiler = 0;
            }
            int returnExisteAlquiler = existealquiler.verificarAlquilerFecha(fechaArriboDateChooser.getDate(), fechaPartidaDateChooser.getDate(), idAlquiler, (UnidadesAlojamiento) unidadAlojamientoComboBox.getSelectedItem());

            if (returnExisteAlquiler == 0) {
                try {
                    if (!editando) {
                        nuevoAction();
                    }
                    logs = new Logs();
                    logs.setUsuario(usuario);
                    a.setFechaArribo(fechaArriboDateChooser.getDate());
                    a.setFechaPartida(fechaPartidaDateChooser.getDate());
                    a.setTipoAlquiler(tipoAlquiler);
                    a.setCantidadPersonas((Integer) cantidadPersonasComboBox.getSelectedItem());
                    a.setIdCliente(cliente);
                    a.setIdUnidadAlojamiento((UnidadesAlojamiento) unidadAlojamientoComboBox.getSelectedItem());
                    a.setMontoTotal(Double.valueOf(montoTotalField.getText()));
                    a.setMontoReserva(Double.valueOf(montoReservaField.getText()));
                    if (a.getMontoReserva().equals(Double.valueOf("0.0"))) {
                        a.setTipoAlquiler("R");
                    } else {
                        if (a.getTipoAlquiler().equals("R")) {
                            a.setTipoAlquiler("F");
                        }
                    }
                    if ((a.getMontoReserva().compareTo(montoReservaAnterior) > 0) && !(montoReservaAnterior.compareTo(a.getMontoTotal()) == 0)) {
                        movCaja = new Caja();
                        movCaja.setFecha(new Date());
                        if (montoReservaAnterior.equals(0.0)) {
                            importe = a.getMontoReserva() * monedaActual.getCambio();
                        } else {
                            importe = (a.getMontoReserva() - montoReservaAnterior) * monedaActual.getCambio();
                        }
                        a.setMontoReserva(montoReservaAnterior + importe);
                        movCaja.setImporte(importe);
                        movCaja.setMoneda(monedaActual.getClave());
                        movCaja.setObservaciones(VistaNuevaReserva.identificarReferencia(a) + "ID: " + a.getIdAlquiler());
                        movCaja.setOperacion(VistaNuevaReserva.identificarOperacion(entityManager, a.getMontoReserva().doubleValue()));
                        movCaja.setResponsable(usuario.getIdUsuario());
                        entityManager.persist(movCaja);

                        /*
                         * if (editando) { entityManager.merge(a); editando =
                         * false; } if (a.getIdAlquiler() == null) {
                         * entityManager.getTransaction().commit();
                         * entityManager.getTransaction().begin(); Integer
                         * idReserva = getIDReserva(a.getIdUnidadAlojamiento(),
                         * a.getIdCliente(), a.getFechaArribo(),
                         * a.getFechaPartida());
                         * logs.setearObservaciones("Alta", "Reservas",
                         * idReserva, "AltaReservas"); } else {
                         * logs.setearObservaciones("Modificación", "Reservas",
                         * a.getIdAlquiler(), "AltaReservas"); }
                         * entityManager.persist(logs);
                         * entityManager.getTransaction().commit();
                         * entityManager.getTransaction().begin();
                         */
                    } else {
                        if (montoReservaAnterior.compareTo(a.getMontoTotal()) == 0) {
                            if (a.getMontoReserva().compareTo(montoReservaAnterior) != 0) {
                                JOptionPane.showMessageDialog(null, "Alquiler ya pagado. No se puede modificar el monto de reserva");
                            } else {
                                entityManager.merge(a);
                            }
                        }
                    }
                    if (editando) {
                        entityManager.merge(a);
                        editando = false;
                    }
                    if (a.getIdAlquiler() == null) {
                        entityManager.getTransaction().commit();
                        entityManager.getTransaction().begin();
                        Integer idReserva = getIDReserva(a.getIdUnidadAlojamiento(), a.getIdCliente(), a.getFechaArribo(), a.getFechaPartida());
                        logs.setearObservaciones("Alta", "Reservas", idReserva, "AltaReservas");
                    } else {
                        logs.setearObservaciones("Modificación", "Reservas", a.getIdAlquiler(), "AltaReservas");
                    }
                    entityManager.persist(logs);
                    entityManager.getTransaction().commit();
                    entityManager.getTransaction().begin();
                } catch (RollbackException rex) {
                    rex.printStackTrace();
                    entityManager.getTransaction().begin();
                    List<entities.Alquileres> merged = new ArrayList<entities.Alquileres>(list.size());
                    for (entities.Alquileres a : list) {
                        merged.add(entityManager.merge(a));
                    }
                    list.clear();
                    list.addAll(merged);
                }
                habilitarBotones(false);
                refrescar();
                habilitarBotonesBusqueda(true);
                if (idReserva != null) {
                    this.frame.dispose();
                }
            } else if (returnExisteAlquiler == 2) {
                JOptionPane.showMessageDialog(this, "La Fecha de Arribo no puede ser mayor que la Fecha de Partida ", "Atención", JOptionPane.ERROR_MESSAGE, null);
            } else {
                JOptionPane.showMessageDialog(this, "Ya existe una Reserva creada para ese rango de Fecha y ese Departamento", "Atención", JOptionPane.ERROR_MESSAGE, null);
            }
        }
    }//GEN-LAST:event_guardarButtonActionPerformed

    private void reservaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reservaRadioButtonActionPerformed
        tipoAlquiler = "R";
    }//GEN-LAST:event_reservaRadioButtonActionPerformed

    private void agregarClienteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarClienteButtonActionPerformed
        if ((MenuPrincipal.frameCreado(nuevoCliente)) && (MenuPrincipal.frameCerrado(nuevoCliente.getFrame()))) {
            nuevoCliente = null;
        }
        if (!MenuPrincipal.frameCreado(nuevoCliente)) {
            nuevoCliente = new AltaClienteReserva(usuario, null, true);
            nuevoCliente.main(usuario, true);
        } else {
            if (!MenuPrincipal.frameVisible(nuevoCliente.getFrame())) {
                MenuPrincipal.rearmarFrame(nuevoCliente.getFrame());
            }
            nuevoCliente.getFrame().toFront();
        }



    }//GEN-LAST:event_agregarClienteButtonActionPerformed
    public static void setearCliente(Clientes clienteRecibido) {
        cliente = clienteRecibido;
        clienteTextField.setText(cliente.getApellido() + ", " + cliente.getNombres());
    }
    private void reservaFirmeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reservaFirmeRadioButtonActionPerformed
        tipoAlquiler = "F";
    }//GEN-LAST:event_reservaFirmeRadioButtonActionPerformed

    private void ocupadoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocupadoRadioButtonActionPerformed
        tipoAlquiler = "O";
    }//GEN-LAST:event_ocupadoRadioButtonActionPerformed

    private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
        refrescar();        // TODO add your handling code here:
    }//GEN-LAST:event_cancelarButtonActionPerformed

    private void masterTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_masterTableMouseClicked
        if (masterTable.getSelectedRow() != -1) {
            a = list.get(masterTable.getSelectedRow());
            Date fechaArribo = (Date) masterTable.getValueAt(masterTable.getSelectedRow(), 4);
            Date fechaPartida = (Date) masterTable.getValueAt(masterTable.getSelectedRow(), 5);
            fechaArriboDateChooser.setDate(fechaArribo);
            fechaPartidaDateChooser.setDate(fechaPartida);

            cliente = (Clientes) masterTable.getModel().getValueAt(masterTable.getSelectedRow(), 2);
            setearCliente(cliente);
            cantidadPersonasComboBox.setSelectedItem(new Integer(list.get(masterTable.getSelectedRow()).getCantidadPersonas()));
            UnidadesAlojamiento unidadAlojamiento = (UnidadesAlojamiento) masterTable.getValueAt(masterTable.getSelectedRow(), 1);
            unidadAlojamientoComboBox.setSelectedItem(unidadAlojamiento);
            setearCantidadPersonasComboBox();
            Double montoTotal = Double.parseDouble(masterTable.getValueAt(masterTable.getSelectedRow(), 6).toString());
            montoTotalField.setText(String.valueOf(montoTotal));
            Double montoReserva = Double.parseDouble(masterTable.getValueAt(masterTable.getSelectedRow(), 7).toString());
            montoReservaField.setText(String.valueOf(montoReserva));
            //tipoAlquiler = (String) masterTable.getValueAt(masterTable.getSelectedRow(), 3);
            tipoAlquiler = a.getTipoAlquiler();
            if ("R".equals(tipoAlquiler)) {
                reservaRadioButton.setSelected(true);
            } else {
                reservaFirmeRadioButton.setSelected(true);
            }
            editando = true;
            habilitarBotones(true);
            habilitarBotonesBusqueda(false);
            sendEmail.setEnabled(true);
            montoReservaAnterior = a.getMontoReserva();
        }
    }//GEN-LAST:event_masterTableMouseClicked

    private void montoTotalFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_montoTotalFieldKeyTyped
        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*
                 * corresponde a BACK_SPACE
                 */)) {
            evt.consume();  // ignorar el evento de teclado
        }       // TODO add your handling code here:
        // TODO add your handling code here:
    }//GEN-LAST:event_montoTotalFieldKeyTyped

    private void montoReservaFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_montoReservaFieldKeyTyped
        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*
                 * corresponde a BACK_SPACE
                 */)) {
            evt.consume();  // ignorar el evento de teclado
        }       // TODO add your handling code here:
        // TODO add your handling code here:
    }//GEN-LAST:event_montoReservaFieldKeyTyped

    private void ayudaLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ayudaLabelMouseEntered
        ayudaLabel.setToolTipText("En esta pantalla usted podra agregar,\n editar y eliminar unidades de alojamiento");
    }//GEN-LAST:event_ayudaLabelMouseEntered

    private void unidadAlojamientoComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_unidadAlojamientoComboBoxFocusLost
        setearCantidadPersonasComboBox();
    }//GEN-LAST:event_unidadAlojamientoComboBoxFocusLost

    private void checkInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInButtonActionPerformed
        // Aca le paso los datos a Generador de Documentos para que cree el documento de checkin

        Calendar cal = Calendar.getInstance();
        Calendar calArribo = Calendar.getInstance();

        Date fechaPartida = ((Date) (masterTable.getValueAt(masterTable.getSelectedRow(), 5)));
        cal.setTime(fechaPartida);
        String fechaPartidaStr = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + (cal.get(Calendar.YEAR));


        Date fechaArribo = ((Date) (masterTable.getValueAt(masterTable.getSelectedRow(), 4)));
        calArribo.setTime(fechaArribo);


        String diaArribo = String.valueOf(calArribo.get(Calendar.DATE));
        String mesArribo = String.valueOf((calArribo.get(Calendar.MONTH) + 1));
        String anioArribo = String.valueOf(calArribo.get(Calendar.YEAR));
        String clienteContrato = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 2));
        String unidad = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 1));
        String personas = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 8));
        String total = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 6));
        String codigo = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 0));
        String documento = ((Clientes) masterTable.getValueAt(masterTable.getSelectedRow(), 2)).getDocumento();

        GeneradorDocumentos generadorDocumentos = new GeneradorDocumentos();
        generadorDocumentos.imprimirTarjetaCheckIn(codigo, documento, diaArribo, mesArribo, anioArribo, personas, clienteContrato, unidad, fechaPartidaStr, total);
    }//GEN-LAST:event_checkInButtonActionPerformed

    private void contratoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contratoButtonActionPerformed
        Calendar cal = Calendar.getInstance();
        Calendar calArribo = Calendar.getInstance();

        Date fechaPartida = ((Date) (masterTable.getValueAt(masterTable.getSelectedRow(), 5)));
        cal.setTime(fechaPartida);
        String fechaPartidaStr = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + (cal.get(Calendar.YEAR));


        Date fechaArribo = ((Date) (masterTable.getValueAt(masterTable.getSelectedRow(), 4)));
        calArribo.setTime(fechaArribo);


        String diaArribo = String.valueOf(calArribo.get(Calendar.DATE));
        String mesArribo = String.valueOf((calArribo.get(Calendar.MONTH) + 1));
        String anioArribo = String.valueOf(calArribo.get(Calendar.YEAR));
        String clienteContrato = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 2));
        String unidad = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 1));
        String personas = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 8));
        String total = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 6));
        String codigo = String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 0));
        String documento = ((Clientes) masterTable.getValueAt(masterTable.getSelectedRow(), 2)).getDocumento();

        GeneradorDocumentos generadorDocumentos = new GeneradorDocumentos();
        generadorDocumentos.imprimirContrato(codigo, documento, diaArribo, mesArribo, anioArribo, personas, clienteContrato, unidad, fechaPartidaStr, total);

    }//GEN-LAST:event_contratoButtonActionPerformed

    private void buscarClienteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarClienteButtonActionPerformed
        if ((MenuPrincipal.frameCreado(buscarCliente)) && (MenuPrincipal.frameCerrado(buscarCliente.getFrame()))) {
            buscarCliente = null;
        }
        if (!MenuPrincipal.frameCreado(buscarCliente)) {
            buscarCliente = new BusquedaCliente(null, true);
            buscarCliente.main(true);
        } else {
            if (!MenuPrincipal.frameVisible(buscarCliente.getFrame())) {
                MenuPrincipal.rearmarFrame(buscarCliente.getFrame());
            }
            buscarCliente.getFrame().toFront();
        }
    }//GEN-LAST:event_buscarClienteButtonActionPerformed

    private void canceladaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_canceladaRadioButtonActionPerformed
        tipoAlquiler = "C";
    }//GEN-LAST:event_canceladaRadioButtonActionPerformed

    private void reservaBusquedaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reservaBusquedaRadioButtonActionPerformed
        tipoBusqueda = "R";
    }//GEN-LAST:event_reservaBusquedaRadioButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        refrescar();
        setearComboBox();
    }//GEN-LAST:event_resetButtonActionPerformed

    private void reservaFirmeBusquedaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reservaFirmeBusquedaRadioButtonActionPerformed
        tipoBusqueda = "F";
    }//GEN-LAST:event_reservaFirmeBusquedaRadioButtonActionPerformed
    private void actualizaTabla() {
        String apellido;
        Query query;
        apellido = apellidoField.getText();
        Date fechaPartida = fechaPartidaDateChooser1.getDate();
        Date fechaArribo = fechaArriboDateChooser1.getDate();
        UnidadesAlojamiento unidadAlojamiento = (UnidadesAlojamiento) unidadAlojamientoBusquedaComboBox.getSelectedItem();
        Calendar fechaPartidaFinal, fechaArriboInicial;

        if (unidadAlojamiento.getNombre().equals("TODOS")) {
            unidadAlojamiento = null;
        }
        if (fechaPartidaDateChooser1.getDate() == null) {
            fechaPartidaFinal = Calendar.getInstance();
            fechaPartidaFinal.set(Calendar.YEAR, 9999);
            fechaPartida = fechaPartidaFinal.getTime();
        }
        if (fechaArriboDateChooser1.getDate() == null) {
            fechaArriboInicial = Calendar.getInstance();
            fechaArriboInicial.set(Calendar.YEAR, 1900);
            fechaArribo = fechaArriboInicial.getTime();
        }
        if (ambasReservasBusquedaRadioButton.isSelected()) {
            query = entityManager.createNamedQuery("Alquileres.findByTodo").setParameter("apellidoCliente", apellido).setParameter("UnidadAlojamiento", unidadAlojamiento).setParameter("fechaFin", fechaPartida).setParameter("fechaInicio", fechaArribo).setParameter("tipoalquiler", "R").setParameter("tipoalquiler2", "F");
        } else {
            query = entityManager.createNamedQuery("Alquileres.findByTodo").setParameter("apellidoCliente", apellido).setParameter("UnidadAlojamiento", unidadAlojamiento).setParameter("fechaFin", fechaPartida).setParameter("fechaInicio", fechaArribo).setParameter("tipoalquiler", tipoBusqueda).setParameter("tipoalquiler2", "");
        }

        listactualizaTabla = query.getResultList();

        list.clear();
        list.addAll(listactualizaTabla);
        if (list.isEmpty()) {
            JOptionPane.showMessageDialog(this, "No se encontro ningun resultado, revise los campos de busqueda", "Atención", JOptionPane.INFORMATION_MESSAGE, null);
        }


    }
    private void buscarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarButtonActionPerformed
        habilitarBotonesBusqueda(true);
        actualizaTabla();
    }//GEN-LAST:event_buscarButtonActionPerformed

    private void exportarExcelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportarExcelButtonActionPerformed
        new ExcelJTableExporter(masterTable, "Reservas").export();
    }//GEN-LAST:event_exportarExcelButtonActionPerformed

    private void sendEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendEmailActionPerformed
        if (("".equals(montoReservaField.getText())) || ("".equals(montoTotalField.getText())) || ("".equals(clienteTextField.getText())) || (unidadAlojamientoComboBox.getSelectedIndex()) < 0 || (fechaArriboDateChooser.getDate() == null) || (fechaPartidaDateChooser.getDate() == null)) {
            JOptionPane.showMessageDialog(this, "Debe completar todos los campos, antes de enviar un Email", "Atención", JOptionPane.INFORMATION_MESSAGE, null);
        } else {
            if (!"".equals(cliente.getEmail())) {
                {
                    int i = JOptionPane.showConfirmDialog(this, "Desea enviar mail de confirmación de reserva al cliente?", "Enviar e-mail", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                    if (i == 0) {

                        //Busqueda de datos de configuración
                        ConfiguracionMail configMail = entityManager.find(ConfiguracionMail.class, 1);

                        //Envio mail de confirmación


                        Date llegadaCalendar = fechaArriboDateChooser.getDate();
                        Date partidaCalendar = fechaPartidaDateChooser.getDate();
                        String codigo = ((Integer) (masterTable.getValueAt(masterTable.getSelectedRow(), 0))).toString();
                        String llegada = String.valueOf(llegadaCalendar.getDate()) + "/" + String.valueOf(llegadaCalendar.getMonth() + 1) + "/" + String.valueOf(llegadaCalendar.getYear() + 1900);
                        String partida = String.valueOf(partidaCalendar.getDate()) + "/" + String.valueOf(partidaCalendar.getMonth() + 1) + "/" + String.valueOf(partidaCalendar.getYear() + 1900);

                        String smtpHost = configMail.getSmtpHostmail();
                        Integer port = configMail.getPortMail();
                        String fromMail = configMail.getFromMail();
                        String user = configMail.getUserMail();
                        String pass = configMail.getPassMail();

                        String toMail = cliente.getEmail().toString();
                        String textMail = "CONFIRMACION DE RESERVA\n\nNombre y Apellido: " + cliente.getNombres() + " " + cliente.getApellido()
                                + "\nCodigo de Reserva: " + codigo
                                + "\nCheck-in: " + llegada
                                + "\nCheck-out: " + partida
                                + "\nCantidad de Personas: " + cantidadPersonasComboBox.getSelectedItem().toString()
                                + "\nSe aloja en: " + String.valueOf(masterTable.getValueAt(masterTable.getSelectedRow(), 1))
                                + "\nTotal del Alquiler: $" + montoTotalField.getText().toString();

                        MailSender mailSender = new MailSender();
                        mailSender.sendEmail(smtpHost, port, fromMail, user, pass, toMail, textMail);
                    }

                }
            } else {
                JOptionPane.showMessageDialog(this, "No se encontro ningun Email asociado al Cliente", "Atención", JOptionPane.INFORMATION_MESSAGE, null);
            }
        }
    }//GEN-LAST:event_sendEmailActionPerformed
    private void habilitarBotonesBusqueda(boolean estado) {
        apellidoField.setEnabled(estado);
        unidadAlojamientoBusquedaComboBox.setEnabled(estado);
        fechaArriboDateChooser1.setEnabled(estado);
        fechaPartidaDateChooser1.setEnabled(estado);
        reservaBusquedaRadioButton.setEnabled(estado);
        reservaFirmeBusquedaRadioButton.setEnabled(estado);
        ambasReservasBusquedaRadioButton.setEnabled(estado);
        resetButton.setEnabled(estado);
        buscarButton.setEnabled(estado);
    }

    private void limpiarCamposBusqueda() {
        apellidoField.setText("");
        unidadAlojamientoBusquedaComboBox.setSelectedIndex(0);
        fechaArriboDateChooser1.setDate(null);
        fechaPartidaDateChooser1.setDate(null);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregarClienteButton;
    private javax.swing.JRadioButton ambasReservasBusquedaRadioButton;
    private javax.swing.JTextField apellidoField;
    private javax.swing.JLabel apellidoLabel;
    private javax.swing.JLabel ayudaLabel;
    private javax.swing.JButton buscarButton;
    private javax.swing.JButton buscarClienteButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JRadioButton canceladaRadioButton;
    private javax.swing.JButton cancelarButton;
    private javax.swing.JComboBox cantidadPersonasComboBox;
    private javax.swing.JLabel cantidadPersonasLabel;
    private javax.swing.JButton checkInButton;
    private static javax.swing.JTextField clienteTextField;
    private java.util.List<entities.Clientes> clientesList;
    private java.util.List<entities.Clientes> clientesList1;
    private java.util.List<entities.Clientes> clientesList2;
    private javax.persistence.Query clientesQuery;
    private javax.persistence.Query clientesQuery1;
    private javax.persistence.Query clientesQuery2;
    private javax.swing.JButton contratoButton;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JLabel estadoAlquilerLabel;
    private javax.swing.JButton exportarExcelButton;
    private com.toedter.calendar.JDateChooser fechaArriboDateChooser;
    private com.toedter.calendar.JDateChooser fechaArriboDateChooser1;
    private javax.swing.JLabel fechaArriboLabel;
    private javax.swing.JLabel fechaArriboLabel1;
    private com.toedter.calendar.JDateChooser fechaPartidaDateChooser;
    private com.toedter.calendar.JDateChooser fechaPartidaDateChooser1;
    private javax.swing.JLabel fechaPartidaLabel;
    private javax.swing.JButton guardarButton;
    private javax.swing.JLabel idClienteLabel;
    private javax.swing.JLabel idUnidadAlojamientoLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private java.util.List<entities.Alquileres> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JTextField montoReservaField;
    private javax.swing.JLabel montoReservaLabel;
    private javax.swing.JTextField montoTotalField;
    private javax.swing.JLabel montoTotalLabel;
    private javax.swing.JButton nuevoButton;
    private javax.swing.JRadioButton ocupadoRadioButton;
    private javax.persistence.Query query;
    private javax.swing.JRadioButton reservaBusquedaRadioButton;
    private javax.swing.JRadioButton reservaFirmeBusquedaRadioButton;
    private javax.swing.JRadioButton reservaFirmeRadioButton;
    private javax.swing.JRadioButton reservaRadioButton;
    private javax.swing.JButton resetButton;
    private javax.swing.JButton sendEmail;
    private javax.swing.JComboBox unidadAlojamientoBusquedaComboBox;
    private javax.swing.JComboBox unidadAlojamientoComboBox;
    private javax.swing.JLabel unidadAlojamientoLabel;
    private java.util.List<entities.UnidadesAlojamiento> unidadesAlojamientoList;
    private java.util.List<entities.UnidadesAlojamiento> unidadesAlojamientoList1;
    private javax.persistence.Query unidadesAlojamientoQuery;
    private javax.persistence.Query unidadesAlojamientoQuery1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public static void main(Usuarios user, Integer idReser) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;


                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AltaReservas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AltaReservas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AltaReservas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AltaReservas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /*
         * Create and display the form
         */
        final Usuarios usuario = user;
        final Integer idReserva = idReser;
        AltaReservas.frame = new JFrame();
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                frame.setContentPane(new AltaReservas(usuario, idReserva));
                frame.pack();
                frame.setVisible(true);
                frame.setTitle("Administracion   -   Reservas   -   Sistema Integrado de Administración de Alquileres Turísticos  ");
                frame.setIconImage(new ImageIcon(getClass().getResource("/images/logo.png")).getImage());
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                frame.addWindowListener(new WindowAdapter() {

                    public void windowClosing(WindowEvent e) {
                        if (frame != null) {
                            frame.setVisible(false);
                        }
                        frame = null;
                    }
                });
            }
        });
    }
}
